package Connectdata;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author annt60258
 */
import Model.DBUtil;
import java.util.*;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class connectdatabase {
   public java.sql.Connection con_connect =null;
public java.sql.Statement s_connect=null;
public java.sql.ResultSet rs_connect=null;
    public void connect(String database,String user,String pass)
    {
        String url_connect=
"jdbc:sqlserver://ANNT60258-PC:1433;databaseName="+database;
String id_connect= user;
String pass_connect = pass;
try{

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con_connect = java.sql.DriverManager.getConnection(url_connect, id_connect, pass_connect);

}       catch (SQLException ex) {
            Logger.getLogger(connectdatabase.class.getName()).log(Level.SEVERE, null, ex);
        }catch(ClassNotFoundException cnfex){
cnfex.printStackTrace();

}

    }
    public void connectstring(String connectstring  )
    {
        String sql_connect = connectstring;
try{
s_connect = con_connect.createStatement();
rs_connect = s_connect.executeQuery(sql_connect);
    }
catch(Exception e){
    e.printStackTrace();
}
    }
    public int demsorow(String connectstring)
    {
        int demrow =0;
        String sql_connect = connectstring;
try{
s_connect = con_connect.createStatement();
rs_connect = s_connect.executeQuery(sql_connect);
while(rs_connect.next())
{
    demrow++;
}
    }
catch(Exception e){
    e.printStackTrace();
}
       return demrow;
    }

    public void connect()
    {
        DBUtil dbutil = new DBUtil();


try{

Class.forName(dbutil.getDriverName());
DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
con_connect = java.sql.DriverManager.getConnection(dbutil.getURL(),dbutil.getUsername(),dbutil.getPassword());

}       catch (SQLException ex) {
            Logger.getLogger(connectdatabase.class.getName()).log(Level.SEVERE, null, ex);
        }catch(ClassNotFoundException cnfex){
cnfex.printStackTrace();

}

    }


}
